package org.poem.fullhandler;

import org.poem.ExecTaskDetailPlanVO;
import org.poem.TaskDetailAvailabilityMaps;
import org.poem.component.MysqlTransformOutComponent;
import org.poem.handler.full.AbstractClientFullHandler;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @author poem
 */
public abstract class DatabasesClientFullHandler extends AbstractClientFullHandler {


    /**
     * 数据库的类型
     */
    protected abstract void setAppSchema(ExecTaskDetailPlanVO execTaskDetailPlanVO);

    /**
     * 获取资源的jdbc
     *
     * @return jdbc
     */
    protected abstract JdbcTemplate getSourceJdbcTemplate(ExecTaskDetailPlanVO execTaskDetailPlanVO);

    /**
     * 获取资目标jdbc
     *
     * @return jdbc
     */
    protected abstract JdbcTemplate getAppJdbcTemplate(ExecTaskDetailPlanVO execTaskDetailPlanVO);

    /**
     * 开始导数据了
     *
     * @param dataTransformVO 信息
     * @throws Exception
     */
    @Override
    public void handle(ExecTaskDetailPlanVO dataTransformVO) throws Exception {
        this.setAppSchema(dataTransformVO);
        MysqlTransformOutComponent mysqlTransformOutComponent = new MysqlTransformOutComponent();
        Integer availability = TaskDetailAvailabilityMaps.getAvailability(dataTransformVO.getTargetTable());
        if (availability == 1) {
            mysqlTransformOutComponent.importData(dataTransformVO, getSourceJdbcTemplate(dataTransformVO), getAppJdbcTemplate(dataTransformVO));
        }
    }
}
